package com.afinal.intelligencetrash.dagger.module;

import android.support.v7.app.AppCompatActivity;


import com.afinal.intelligencetrash.ui.activity.LoginActivity;
import com.afinal.intelligencetrash.ui.activity.RegisterActivity;
import com.afinal.intelligencetrash.ui.base.BaseView;
import com.afinal.intelligencetrash.ui.interfaces.LoginView;
import com.afinal.intelligencetrash.ui.interfaces.RegisterView;

import java.util.HashMap;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

/**
 * Created by cyy on 17-10-10.
 */
@Singleton
@Module
public class ActivityModule {

    private HashMap<Class<? extends AppCompatActivity>, BaseView> activityHashMap = new HashMap<>();

    private ActivityModule() {

    }


    @Provides
    public LoginView provideLoginView(){
        BaseView activity = activityHashMap.get(LoginActivity.class);
        if(activity == null){
            throw new RuntimeException("");
        }
        activityHashMap.remove(LoginActivity.class);
        return (LoginView) activity;
    }

    @Provides
    public RegisterView provideRegisterView(){
        BaseView activity = activityHashMap.get(RegisterActivity.class);
        if(activity == null){
            throw new RuntimeException("");
        }
        activityHashMap.remove(RegisterActivity.class);
        return (RegisterView) activity;
    }

    public void addActivity(Class<? extends AppCompatActivity> clazz, BaseView view){
        activityHashMap.put(clazz, view);
    }


    public static ActivityModule getInstance(){
        return ActivityModuleHolder.instance;
    }



    private static class ActivityModuleHolder{
        public static ActivityModule instance = new ActivityModule();
    }
}
